/*
 * @Descripttion:
 * @version: 1.0.0
 * @Author: htang
 * @Date: 2024-01-29 14:03:40
 * @LastEditors: htang
 * @LastEditTime: 2024-01-29 15:03:52
 */
import { defHttp } from '/@/utils/http/axios';
import { createVNode } from 'vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal, message } from 'ant-design-vue';

const API = {
  // 设备心跳分页
  page: '/equipment-heartbeat/page',
  // 设备心跳列表
  list: '/equipment-heartbeat/list',
  // 增加设备心跳
  add: '/equipment-heartbeat/add',
  // 编辑设备心跳
  modify: '/equipment-heartbeat/modify',
  // 删除设备心跳
  delete: '/equipment-heartbeat/delete',
  // 设备心跳基础信息
  info: '/equipment-heartbeat/info',
}

/**
 * 获取设备心跳分页列表
 * @param {int} current 当前页
 * @param {int} size 当前页总数
 * @returns
 */
export const equipmentHearbeatPageApi = async (params) => {
  return await defHttp.get({ url: API.page, params });
}

/**
 * 获取设备心跳列表
 * @returns
 */
export const equipmentHearbeatListApi = async (params) => {
  return await defHttp.get({ url: API.list, params });
}

/**
 * 根据ID获取设备心跳数据
 * @param {int} id
 * @returns
 */
export const equipmentHearbeatInfoApi = async (params) => {
  return await defHttp.get({ url: API.info, params });
}

/**
 * 新增设备心跳数据
 * @param {int} data 心跳数据
 * @param {int} equipmentCode 设备编码
 * @param {int} status 心跳状态
 * @param {int} time 时间
 * @returns
 */
export const equipmentHearbeatAddApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.add, data }).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 编辑设备心跳数据
 * @param {int} data 心跳数据
 * @param {int} equipmentCode 设备编码
 * @param {int} status 心跳状态
 * @param {int} time 时间
 * @returns
 */
export const equipmentHearbeatModifyApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.modify, data }).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 删除设备心跳数据
 * @param {*} id
 * @returns
 */
export const equipmentHearbeatDeleteApi = (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定删除当前设备心跳数据?',
      centered: true,
      onOk() {
        resolve(defHttp.post({ url: API.delete, data }))
      }, onCancel() {
        message.warning('已取消');
        reject();
      },
    });
  })
}